const Koa = require('koa')
const app = new Koa()
const mongoose = require('mongoose')
const Router = require('koa-router')
let user = require('./appApi/User.js')
let goods = require('./appApi/goods.js')
const bodyParser = require('koa-bodyparser')
app.use(bodyParser()); //打通前后端,解析数据
const cors = require('koa2-cors')
app.use(cors()); //支持跨域


let router = new Router();
router.use('/user', user.routes())
router.use('/goods', goods.routes())

app.use(router.routes()) //路由
app.use(router.allowedMethods()) //使用中间件



//引入连接，并立即执行
const {
  connect,
  initSchemas
} = require('./database/init.js');


;(async () => {
  await connect()
  initSchemas()

})()


// app.use(async (ctx)=>{
//     ctx.body = "<h1>你好，世界</h1>"
// });
app.listen(3000, function () {
  console.log('succee');
});

